package com.gzj.environment.controller;

import com.gzj.environment.framework.annotation.RefuseResponseResult;
import com.gzj.environment.framework.annotation.ResponseResult;
import com.gzj.environment.model.collectData.criteria.QueryCriteria;
import com.gzj.environment.module.collectData.context.ClientContext;
import com.gzj.environment.module.collectData.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/collectData/manager")
@ResponseResult
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    /**
     * 根据条件查询客户端版本号
     * @param criteria 查询条件
     * @return
     */
    @GetMapping("/query")
    public Map<String, String> queryVersion(QueryCriteria criteria) {
        return managerService.queryVersion(criteria);
    }

    /**
     * 根据查询条件，对指定的信道发送获取版本的命令
     * @param criteria 查询条件
     */
    @GetMapping("/send")
    public void sendVersionCmd(QueryCriteria criteria) {
        managerService.sendVersionCmd(criteria);
    }

    /**
     * 查看所有数据
     * @return
     */
    @GetMapping("/showAllData")
    @RefuseResponseResult
    public Map<String, Object> getClientMap() {
        Map<String, Object> wholeDataMap = new HashMap<>();
        wholeDataMap.put("client", ClientContext.getClientMap());
        wholeDataMap.put("version", ClientContext.getVersionMap());
        return wholeDataMap;
    }
}
